//
//  SearchTeacherCell.m
//  GC_OC
//
//  Created by Macbook Pro on 2023/4/25.
//

#import "SearchTeacherCell.h"
#import "Teacher.h"

@interface SearchTeacherCell ()

@property (nonatomic, weak) UIImageView *picView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *sexLabel;
@property (nonatomic, weak) UILabel *mobileLabel;
@property (nonatomic, weak) UILabel *descLabel;

@end

@implementation SearchTeacherCell

- (void)setupSubviews
{
    [super setupSubviews];
    
    UIImageView *picView = [[UIImageView alloc] init];
    [self.contentView addSubview:picView];
    self.picView = picView;
//    picView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    picView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5000].CGColor;
    picView.layer.shadowOffset = CGSizeMake(0,2);
    picView.layer.shadowOpacity = 1;
    picView.layer.shadowRadius = 4;
    
    UILabel *nameLabel = [UILabel fk_labelWithFont:fk_adjustFont(24) textColor:UIColor.blackColor];
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    UILabel *sexLabel = [UILabel fk_labelWithFont:fk_adjustFont(10) textColor:fkColor333333];
    [self.contentView addSubview:sexLabel];
    self.sexLabel = sexLabel;
    
    UILabel *mobileLabel = [UILabel fk_labelWithFont:fk_adjustFont(16) textColor:fkColor333333];
    [self.contentView addSubview:mobileLabel];
    self.mobileLabel = mobileLabel;
    
    UILabel *descLabel = [UILabel fk_labelWithFont:fk_adjustFont(16) textColor:fkColor333333];
    [self.contentView addSubview:descLabel];
    self.descLabel = descLabel;
    descLabel.numberOfLines = 0;
    
    [picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(fk_adjustW(90));
        make.height.offset(fk_adjustW(124));
        make.centerY.offset(0);
        make.left.offset(15);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(picView.mas_right).offset(16);
        make.top.equalTo(picView);
        make.width.mas_lessThanOrEqualTo(fk_adjustW(120));
    }];
    [sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel.mas_right).offset(6);
        make.bottom.equalTo(nameLabel);
    }];
    [mobileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.centerY.equalTo(nameLabel);
    }];
    [descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel);
        make.right.equalTo(mobileLabel);
        make.top.equalTo(nameLabel.mas_bottom).offset(6);
        make.bottom.equalTo(picView);
    }];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[Teacher class]]) {
        Teacher *model = data;
        
        UIImage *defaultAvatar = [UIImage imageNamed:[model.teacher_sex isEqualToString:@"1"] ? @"default_avatar_man" : @"default_avatar_women"];
        [self.picView sd_setImageWithURL:[NSURL URLWithString:model.teacher_image] placeholderImage:defaultAvatar];
        self.nameLabel.text = model.teacher_name;
        self.sexLabel.text = model.sex;
        self.mobileLabel.text = model.teacher_phone;
        self.descLabel.text = [model.teacher_introduce fk_replaceHtmlTag];
        
        // 创建NSMutableParagraphStyle对象
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        // 设置首行缩进2个字符
        paragraphStyle.firstLineHeadIndent = 2 * self.descLabel.font.pointSize;
        // 应用到UILabel的attributedText属性中
        self.descLabel.attributedText = [[NSAttributedString alloc] initWithString:self.descLabel.text attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
    }
}
- (void)setTitlehigh:(NSString *)highText
{
    if (self.nameLabel.text.length > 0) {
        NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowBlurRadius = 4;
        shadow.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5];
        shadow.shadowOffset =CGSizeMake(0,2);
        
        [self.nameLabel setAttribute:self.nameLabel.text diff:highText diffColor:UIColor.redColor diffFont:self.nameLabel.font];
        
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithAttributedString:self.nameLabel.attributedText];
        [attrStr addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, attrStr.length)];
        self.nameLabel.attributedText = attrStr;
    }
}

@end
